<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="物品类型" prop="userName">
            <!-- <el-select
              v-model="queryParams.cateId"
              filterable
              placeholder="请选择"
            >
              <el-option
                v-for="item in fuanlioptions"
                :key="item.id"
                :label="item.houseCabinet"
                :value="item.id"
              >
              </el-option>
            </el-select> -->
             <el-cascader
              v-model="cateIds"
              clearable
              :options="fuanlioptions"
              :props="{
                label: 'houseCabinet',
                value: 'id',
                key:'id',
                children: 'children',
                checkStrictly: true
              }"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="物品名称" prop="userName">
            <el-input
              v-model="queryParams.productName"
              placeholder="请输入产品名称"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
              @clear="resetQuery"
            />
          </el-form-item>
          <!-- <el-form-item label="接收人" prop="userName">
            <el-input
              v-model="queryParams.receiverName"
              placeholder="请输入接收人名称"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
              clear="resetQuery"
            />
          </el-form-item> -->
          <el-form-item label="仓库名称" prop="storeName">
            <el-select
              v-model="queryParams.houseId"
              filterable
              placeholder="请选择"
            >
              <el-option
                v-for="item in cangkuoptions"
                :key="item.id"
                :label="item.warehouseName"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="开始时间">
            <div class="block">
              <el-date-picker
                v-model="queryParams.createTime"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期"
              >
              </el-date-picker>
            </div>
          </el-form-item>
          <el-form-item label="结束时间">
            <div class="block">
              <el-date-picker
                v-model="queryParams.updateTime"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期"
              >
              </el-date-picker>
            </div>
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
            <span style="margin:0 20px">
              <span class="sasa">总价格 : </span>
            <el-input style="width:300px" v-model="numlist" clearable disabled=""> </el-input>
            </span>

           <span> <span class="sasa">入库总件数 : </span>
            <el-input style="width:300px"  v-model="pagelist" clearable disabled=""> </el-input></span>
          </el-form-item>
        </el-form>
        <el-table
          v-loading="loading"
          :data="userList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column type="expand">
            <template slot-scope="props">
              <h3>入库列表</h3>
              <el-table
                :data="props.row.recordList"
                border
                :header-cell-style="{color: '#fff', background:'#409EFF'}"
                style="width: 100%"
              >
                <el-table-column
                  prop="price"
                  align="center"
                  label="单价"
                  width="width"
                >
                </el-table-column>
                <el-table-column
                  prop="unitMount"
                  label="数量"
                  align="center"
                  width="width"
                >
                </el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <!-- <el-table-column type="expand">
            <template slot-scope="scope">
              <el-form>
                <el-form-item label="单价">
                  <span class="priceSpan"  v-for="(item, index) in scope.row.recordList" :key="index">{{item.price}} 元</span>
                </el-form-item>
              </el-form>
              <el-form >
                <el-form-item label="数量">
                  <span class="priceSpan" v-for="(item, index) in scope.row.recordList" :key="index">{{item.unitMount}}{{item.unit}}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column> -->
          <el-table-column
            label="物品类型"
            align="center"
            prop="cateName"
            width="220"
          >
            <!-- <template slot-scope="scope">
              {{ gethouseName11(scope.row.cateId) }}
            </template> -->
          </el-table-column>
          <el-table-column
            label="物品名称"
            align="center"
            prop="productName"
            width="240"
          />
          <el-table-column
            label="储位"
            align="center"
            prop="houseCabinet"
            width="260"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              {{ gethouseName1(scope.row.cabinetId) }}
            </template>
          </el-table-column>
          <el-table-column
            label="入库时间"
            align="center"
            prop="createTime"
            width="280"
          />

          <el-table-column
            label="仓库名称"
            align="center"
            prop="houseName"
            width="260"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              {{ gethouseName(scope.row.houseId) }}
            </template>
          </el-table-column>
          <el-table-column
            label="备注"
            align="center"
            prop="remark"
            width="350"
            :show-overflow-tooltip="true"
          />
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getRecordList"
        />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { storeList, cabinetList } from "@/api/system/stores";
import {
  getRecordList,
  listUser,
  getUser,
  delUser,
  addUser,
  updateUser,
  exportUser,
  resetUserPwd,
  changeUserStatus,
  importTemplate
} from "@/api/system/user";
import { getToken } from "@/utils/auth";

export default {
  name: "User",
  components: {},
  data() {
    return {
      fuanlioptions: [],
      wupinoptions: [],
      cangkuoptions1: [],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      numlist:'',
      pagelist:'',
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      cangkuoptions: [],
      // 表单参数
      form: {},
      // forms: {
      //   nickName: '物品类型',
      //   phonenumber: '',
      //   userName: '物品名称',
      //   storeName: '仓库A',
      //   remark: '',
      //   postIds: [],
      // },
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/user/importData"
      },
      cateIds:[],
      // 查询参数
      queryParams: {
        outIn: 1,
        pageNum: 1,
        pageSize: 10,
        cateId:'',
        houseId: undefined,
        productName: "",
        createTime: "",
        updateTime: "",
        type: 2
      },
      // 列信息
      // columns: [
      //   { key: 0, label: `类型`, visible: true },
      //   { key: 1, label: `名称`, visible: true },
      //   { key: 2, label: `单位`, visible: true },
      //   { key: 3, label: `单位`, visible: true },
      //   { key: 4, label: `数量`, visible: true },
      //   { key: 5, label: `总价`, visible: true },
      //   { key: 6, label: `所属仓库`, visible: true },
      //   { key: 7, label: `创建时间`, visible: true },
      //   { key: 8, label: `添加人`, visible: true },
      //   { key: 9, label: `备注`, visible: true },
      // ],
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "物品名称不能为空", trigger: "blur" }
        ],
        nickName: [
          { required: true, message: "物品类型不能为空", trigger: "blur" }
        ],
        storeName: [
          { required: true, message: "所属仓库不能为空", trigger: "blur" }
        ]
      }
    };
  },
  watch: {},
  created() {
    this.cangku();
    this.chuwei();
    this.getRecordList();
    this.cabinetList();
    this.getDicts("goodType").then(res => {
      this.wupinoptions = res.data;
    });
  },
  methods: {
    typeFormat(row, column) {
      return this.selectDictLabel(this.wupinoptions, row.cateId);
    },
    gethouseName(v) {
      var bbb = this.cangkuoptions.find(function(item) {
        return item.id == v;
      });
      if (bbb) return bbb.warehouseName;
    },
    gethouseName1(v) {
      var aaa = this.cangkuoptions1.find(function(item) {
        return item.id == v;
      });
      if (aaa) return aaa.houseCabinet;
    },
    gethouseName11(v) {
      var aaa = this.fuanlioptions.find(function(item) {
        return item.id == v;
      });
      if (aaa) return aaa.houseCabinet;
    },
    /** 查询用户列表 */

    getRecordList() {
      // this.queryParams.cateId = this.queryParams.cateId.join(",");
      let arr =JSON.parse(JSON.stringify(this.cateIds))
      this.queryParams.cateId = arr.join()
      getRecordList(this.queryParams).then(res => {
        console.log(res);
        if (res.code == 200) {
          this.userList = res.rows;
          this.loading = false;
          this.numlist = res.sumNum;
          this.pagelist = res.statisticsType;
          this.total = res.total;
        }
      });
    },
    cabinetList() {
      cabinetList(this.queryParams).then(res => {
        console.log(res, "-----------AAAAA------");
        if (res.code == 200) {
          this.fuanlioptions = res.rows;
        }
      });
    },
    chuwei() {
      let data = {
        outIn: this.form.outIn,
        pageNum: this.form.pageNum,
        pageSize: this.form.pageSize,
        cateId: this.form.cateId,
        houseId: this.form.houseId,
        productName: this.form.productName,
        createTime: this.form.createTime,
        updateTime: this.form.updateTime,
        type: 1
      };
      cabinetList(data).then(res => {
        console.log(res, "-----------chuwei------------");
        this.cangkuoptions1 = res.rows;
      });
    },
    cangku() {
      storeList().then(res => {
        console.log(res, "-----------仓库列表------------");
        this.cangkuoptions = res.rows;
        console.log(this.cangkuoptions);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userId: undefined,
        deptId: undefined,
        userName: undefined,
        nickName: undefined,
        password: undefined,
        phonenumber: undefined,
        email: undefined,
        sex: undefined,
        status: "0",
        remark: undefined,
        postIds: [],
        roleIds: []
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getRecordList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      (this.queryParams = {
        outIn: 1,
        pageNum: 1,
        pageSize: 10,
        houseId: undefined,
        // productName:"",
        // receiverName:'',
        type: 2
      }),
        this.getRecordList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.userId != undefined) {
            updateUser(this.form).then(res => {
              this.msgSuccess("修改成功");
              this.open = false;
            });
          } else {
            addUser(this.form).then(res => {
              this.msgSuccess("新增成功");
              this.open = false;
            });
          }
        }
      });
    }
  }
};
</script>
<style scoped>
.priceSpan {
  margin-right: 20px;
}
</style>
